package cn.kasa.controller;

import cn.kasa.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/getUserById/{id}")
    public User getUserById(@PathVariable Long id){
        // 请求的url
        String url = "http://user-server/getUserById/" + id;
        // 调用getForObject方法发get请求
        return restTemplate.getForObject(url,User.class);
    }
}
